
//
// 101021 - AH - Created.
// 101116 - AH - getNetwork().
// 110109 - AH - (Hector) Introducing the RetrievalEvent.
// 110110 - AH - Dummy implementation of getInput(List<AttributeObject>).
// 110116 - AH - Removed old code, now interface with NetworkRetrievalStrategy.
// 110117a- AH - (Hector) Renamed getInput(List<AttributeObject>) to
//               getToken(List<AttributeObject>) to be true to terminology.
// 110117b- AH - (Hector) Implemented getTokens(List<AttributeObject>).
// 110709 - AH - (Garage) getOntology().
// 120117 - AH - (Huset) Renamed from *Spoke.
// 120228 - AH - (Zen *) Implemented new Ontology method 
//               getSoekratNames(List<SoekratNames>).
//

package org.soekrat.engine.wheel.ontology;

import java.util.ArrayList;
import java.util.List;

import org.soekrat.AttributeObject;
import org.soekrat.engine.SoekratName;
import org.soekrat.engine.network.Cluster;
import org.soekrat.engine.network.Network;
import org.soekrat.engine.network.NetworkNode;
import org.soekrat.engine.ontology.OntologyDatastructure;
import org.soekrat.engine.retrieval.network.NetworkRetrievalStrategy;
import org.soekrat.engine.retrieval.network.NetworkScan;
import org.soekrat.engine.visitor.Input;
import org.soekrat.engine.wheel.Wheel;
import org.soekrat.engine.wheel.retrieval.RetrievalEvent;
import org.soekrat.engine.wheel.retrieval.RetrievalEventSource;
import org.soekrat.engine.wheel.retrieval.RetrievalEventType;

/**
 * <p>
 *   {@link Network}
 *   {@link Ontology spoke}.
 * </p>
 * @author Arne Halvorsen (AH)
 * @author Laetitia Le Chatton (LLC) 
 */
public final class NetworkOntology extends Ontology 
{
  private final RetrievalEventSource m_source=RetrievalEventSource.NETWORK;
  
  private final RetrievalEventType m_step=RetrievalEventType.STEP;
  
  private final Network m_network;
  
  /**
   * <p>
   *   Constructor.
   * </p>
   * @param wheel
   * @param network
   */
  public NetworkOntology(Wheel wheel, Network network) 
  {
    super(wheel);
    
    if (network==null)
    {
      throw new NullPointerException("network");
    }
    
    m_network=network;
  }
  
  /**
   * <p>
   *   Gets 
   *   {@link Network} {@code this} access.
   * </p>
   * @return {@code Network}.
   */
  public Network getNetwork(){ return m_network; }

  @Override
  public List<SoekratName> getSoekratNames(List<SoekratName> names)
  {
    names=(names==null) ? new ArrayList<SoekratName>() : names;
    
    for (NetworkNode node : m_network) names.add(node.getSoekratName());
    
    return names;
  }

  @Override
  public OntologyDatastructure getOntologyDatastructure(){ return m_network; }
  
  @Override
  protected Object scan(Input tokens) 
  {
    return new NetworkScan(m_network, tokens);
  }

  @Override
  protected RetrievalEvent paint(Object scan, List<AttributeObject> paint)
  {
    RetrievalEvent retVal=new RetrievalEvent("Network", m_step, m_source);
    NetworkRetrievalStrategy.retrieve((NetworkScan)scan, paint, retVal);
    return retVal;
  }

  @Override
  public Input getTokens(List<AttributeObject> paint) 
  {
    Input retVal=new Input();
    
    for (AttributeObject curr : paint)
    {
      if (curr instanceof Cluster)
      {
        Cluster cluster=(Cluster)curr;
        for (NetworkNode node : cluster) 
        {
          retVal.add(node.getName());  
        }
      }
    }
    
    return retVal;
  }
  
  @Override
  public String getName(){ return "Network Ontology"; }
  
}
